/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.terminal_reason;

import moved.org.objectweb.asm.ClassVisitor;
import moved.org.objectweb.asm.MethodVisitor;
import picounit.features.classloader.NullVisitor;

public class ReasonCapturingClassVisitor extends NullVisitor implements ClassVisitor {
	private final ReasonCapturingMethodVisitor reasonCapturingMethodVisitor;
	private String className;

	public ReasonCapturingClassVisitor(ReasonRegistry reasonRegistry) {
		this(new ReasonCapturingMethodVisitor(reasonRegistry));
	}

	public ReasonCapturingClassVisitor(ReasonCapturingMethodVisitor reasonCapturingMethodVisitor) {
		this.reasonCapturingMethodVisitor = reasonCapturingMethodVisitor;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// ClassVisitor
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public void visit(int version, int access, String className, String signature, String superName,
		String[] interfaces) {

		this.className = className.replace('/', '.');
	}

	@Override
	public MethodVisitor visitMethod(int access, String name, String desc, String signature,
		String[] exceptions) {

		return reasonCapturingMethodVisitor.visit(className, name);
	}
}
